<?php

namespace Kunfeng\Dify\Constants;

/**
 * Dify API 路径常量
 */
class ApiPaths
{
    // 对话型应用相关路径
    public const CHAT_MESSAGES = '/chat-messages';
    public const MESSAGES = '/messages';
    public const CONVERSATIONS = '/conversations';
    public const AUDIO_TO_TEXT = '/audio-to-text';
    public const TEXT_TO_AUDIO = '/text-to-audio';
    public const META = '/meta';
    public const STOP = '/stop';
    public const FEEDBACKS = '/feedbacks';
    public const SUGGESTED_QUESTIONS = '/suggested';
    public const NAME = '/name';
    public const APPS_ANNOTATIONS = '/apps/annotations';
    public const APPS_ANNOTATIONS_REPLY = '/apps/annotations-reply';

    // 文本生成应用相关路径
    public const COMPLETION_MESSAGES = '/completion-messages';

    // 工作流应用相关路径
    public const WORKFLOW_RUN = '/workflows/run';
    public const WORKFLOW_RUN_STATUS = '/workflows/run/status';
    public const WORKFLOW_RUN_STOP = '/workflows/run/stop';
    public const WORKFLOW_RUN_LOGS = '/workflows/run/logs';

    // 知识库管理相关路径
    public const DATASETS = '/datasets';
    public const DATASETS_DOCUMENTS = '/datasets/{dataset_id}/documents';
    public const DATASETS_DOCUMENT_SEGMENTS = '/datasets/{dataset_id}/documents/{document_id}/segments';
    public const DATASETS_DOCUMENT_SEGMENT = '/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}';
    public const DATASETS_RETRIEVE = '/datasets/{dataset_id}/retrieve';

    // 文件相关路径
    public const FILES_UPLOAD = '/files/upload';
    public const FILES_PREVIEW = '/files/{file_id}/preview';

    /**
     * 获取知识库文档路径
     */
    public static function getDatasetDocumentsPath(string $datasetId): string
    {
        return str_replace('{dataset_id}', $datasetId, self::DATASETS_DOCUMENTS);
    }

    /**
     * 获取知识库检索路径
     */
    public static function getDatasetRetrievePath(string $datasetId): string
    {
        return str_replace('{dataset_id}', $datasetId, self::DATASETS_RETRIEVE);
    }

    /**
     * 获取文件预览路径
     */
    public static function getFilePreviewPath(string $fileId): string
    {
        return str_replace('{file_id}', $fileId, self::FILES_PREVIEW);
    }

    /**
     * 获取文档分段列表路径
     */
    public static function getDocumentSegmentsPath(string $datasetId, string $documentId): string
    {
        return str_replace(['{dataset_id}', '{document_id}'], [$datasetId, $documentId], self::DATASETS_DOCUMENT_SEGMENTS);
    }

    /**
     * 获取文档分段详情路径
     */
    public static function getDocumentSegmentPath(string $datasetId, string $documentId, string $segmentId): string
    {
        return str_replace(['{dataset_id}', '{document_id}', '{segment_id}'], [$datasetId, $documentId, $segmentId], self::DATASETS_DOCUMENT_SEGMENT);
    }
}
